﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iShoppingBUS;
using iShoppingDTO;

namespace iShopping.Member
{
    public partial class iShopping_Member : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("/Guest/LoginPage.aspx");
            }

            TaiKhoanDTO tk = new TaiKhoanDTO();
            lb_username.Text = (string)Session["username"];

            if (TaiKhoanBUS.LayMaLoaiTK(lb_username.Text) != "2")
            {
                Response.Redirect("/Guest/LoginPage.aspx");
                Session.Remove("username");
            }

            if (IsPostBack == false)
            {
                List<LoaiSanPhamDTO> loaiSanPhamDtos = LoaiSanPhamBUS.LayDSLoaiSanPham();

                dllist.Items.Add(new ListItem("Tất Cả Danh Mục", "LSP000"));
                foreach (LoaiSanPhamDTO loaiSanPhamDto in loaiSanPhamDtos)
                {
                    dllist.Items.Add(new ListItem(loaiSanPhamDto.TenLoaiSanPham, loaiSanPhamDto.MaLoaiSanPham));
                }
                dllist.SelectedIndex = 0;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string sanpham = TextBox1.Text;
            Response.Redirect("~/Member/KetQuaTimKiem.aspx?name=" + sanpham + "&id=" + dllist.SelectedItem.Value + "&pgn=1");

        }

        protected void btnLogOut_Click(object sender, EventArgs e)
        {
            Session.Remove("username");
            Session.Remove("userid");
            Response.Redirect("/Guest/HomePage.aspx");
        }
    }
}
